﻿namespace FFF.Test
{
    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Reflection;
    using System.Text;
    using System.Threading.Tasks;
    using Abp.Application.Services;
    using Microsoft.AspNetCore.Authentication.JwtBearer;
    using Microsoft.AspNetCore.Builder;
    using Microsoft.AspNetCore.Hosting;
    using Microsoft.AspNetCore.Mvc.Razor;
    using Microsoft.Extensions.Configuration;
    using Microsoft.Extensions.DependencyInjection;
    using Microsoft.Extensions.Options;
    using Microsoft.IdentityModel.Tokens;
    using Senparc.CO2NET;
    using Senparc.CO2NET.RegisterServices;
    using Senparc.Weixin;
    using Senparc.Weixin.Entities;
    using Senparc.Weixin.MP;
    using Senparc.Weixin.RegisterServices;
    using Senparc.Weixin.TenPay;
    using Senparc.Weixin.WxOpen;
    using Swashbuckle.AspNetCore.Swagger;
    using Swashbuckle.AspNetCore.SwaggerGen;
    using FFF.Test.Util.Web;

    /// <summary>
    /// 配置视图的查询
    /// </summary>
    public static class ViewsConfigurer
    {
        /// <summary>
        /// 配置视图的查询路径
        /// </summary>
        /// <param name="services">程序的服务对象</param>
        /// <param name="configuration">程序的配置对象</param>
        /// <param name="env">环境节点</param>
        public static void ConfigureServices(IServiceCollection services, IConfiguration configuration, IHostingEnvironment env)
        {
            List<string> viewFolers = new List<string>();

            // 循环areas目录找到文件夹名称
            var folderPath = Server.ContentRootPath + "/" + "Areas";
            foreach (var dicName in Directory.EnumerateDirectories(folderPath))
            {
                var dicNmae = Path.GetFileName(dicName);
                viewFolers.Add($"/Areas/{dicNmae}/Views/{{1}}/{{0}}.cshtml");
            }

            services.Configure<RazorViewEngineOptions>(options =>
            {
                foreach (var viewFoler in viewFolers)
                {
                    options.AreaViewLocationFormats.Add(viewFoler);
                }
            });

        }

        /// <summary>
        /// 文档的配置
        /// </summary>
        /// <param name="app">app环境</param>
        /// <param name="env">env的环境</param>
        public static void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
        }
    }
}
